home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / SCRSIZE.C < prev    next >
C/C++ Source or Header  |  1992-12-30  |  5KB  |  133 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    s c r s i z e .  c                                              */
  3. /*                                                                    */
  4. /*    Report screen size under MS-DOS                                 */
  5. /*                                                                    */
  6. /*    Copyright (c) 1992 by Kendra Electronic Wonderworks.            */
  7. /*    All rights reserved except those explicitly granted by          */
  8. /*    the UUPC/extended license.                                      */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *    $Id: SCRSIZE.C 1.5 1992/12/30 05:27:11 plummer Exp $
  13.  *
  14.  *    $Log: SCRSIZE.C $
  15.  *     Revision 1.5  1992/12/30  05:27:11  plummer
  16.  *     MS C compile fixes
  17.  *
  18.  * Revision 1.4  1992/12/18  12:05:57  ahd
  19.  * Fix query for ANSI sys
  20.  *
  21.  * Revision 1.3  1992/12/11  12:45:11  ahd
  22.  * Use BIOS values if no ANSI driver
  23.  *
  24.  * Revision 1.2  1992/11/29  22:09:10  ahd
  25.  * Add stdlib.h for _osmajor under MSC
  26.  *
  27.  * Revision 1.1  1992/11/27  14:36:10  ahd
  28.  * Initial revision
  29.  *
  30.  */
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*                        System include files                        */
  34. /*--------------------------------------------------------------------*/
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <dos.h>
  39.  
  40. /*--------------------------------------------------------------------*/
  41. /*                    UUPC/extended include files                     */
  42. /*--------------------------------------------------------------------*/
  43.  
  44. #include "lib.h"
  45. #include "scrsize.h"
  46.  
  47. /*--------------------------------------------------------------------*/
  48. /*    s c r s i z e                                                   */
  49. /*                                                                    */
  50. /*    Return screen size under MS-DOS 4.0 and 5.0                     */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. short scrsize( void )
  54. {
  55.  
  56. #ifdef __TURBOC__
  57.    static unsigned char far *bios_rows = MK_FP( 0x0040, 0x0084 );
  58. /* static unsigned char far *bios_cols = MK_FP( 0x40, 0x4a ); */
  59. #else
  60.    static unsigned char far *bios_rows = 0x0484;
  61. #endif
  62.  
  63.    static boolean error = FALSE;
  64.    static short default_rows = 0;
  65.  
  66.    typedef struct _DISPLAYMODE   /* Page 310 MS-DOS 5.0 PGMR Reference */
  67.    {
  68.       char  dmInfoLevel;
  69.       char  dmReserved1;
  70.       short dmDataLength;
  71.       short dmFlags;
  72.       char  dmMode;
  73.       char  dmReserved2;
  74.       short dmColors;
  75.       short dmWidth;
  76.       short dmLength;
  77.       short dmColumns;
  78.       short dmRows;
  79.  
  80.    } DISPLAYMODE;
  81.  
  82.    DISPLAYMODE info;
  83.  
  84.    union REGS regs;
  85.  
  86. /*--------------------------------------------------------------------*/
  87. /*            If an old version of DOS, return stock size             */
  88. /*--------------------------------------------------------------------*/
  89.  
  90.    if ((_osmajor < 4) || error )
  91.       return (short) (default_rows ? default_rows : *bios_rows);
  92.                                  /* Faster, but not well documented  */
  93.  
  94. /*--------------------------------------------------------------------*/
  95. /*             Fill in information to perform processing              */
  96. /*--------------------------------------------------------------------*/
  97.  
  98.    info.dmInfoLevel   = 0;       /* Magic number in book          */
  99.    info.dmReserved1   = 0;       /* Magic number in book          */
  100.    info.dmReserved2   = 0;       /* Magic number in book          */
  101.    info.dmDataLength  = 14;      /* Magic number in book          */
  102.  
  103.    regs.x.bx = 0x0001;           /* STDOUT file handle            */
  104.    regs.h.ch = 0x03;             /* Screen device category        */
  105.    regs.h.cl = 0x7f;             /* Get display mode              */
  106.    regs.x.ax = 0x440c;           /* Video Status                  */
  107.    regs.x.dx = (short) &info;    /* Address of structure          */
  108.  
  109.    intdos(®s, ®s );
  110.  
  111. /*--------------------------------------------------------------------*/
  112. /*    If we have an error, set up to use the BIOS information (or     */
  113. /*    a fixed default) on future calls.  Otherwise, return the        */
  114. /*    ANSI supplied value.                                            */
  115. /*--------------------------------------------------------------------*/
  116.  
  117.    if ( regs.x.cflag )
  118.    {
  119.       if ((*bios_rows < 20 ) || (*bios_rows > 99)) /* Sanity check   */
  120.          default_rows = 24;
  121.  
  122.       printmsg(2,"DOS error %d retrieving screen size, using BIOS value %d",
  123.                   (int) regs.x.ax,
  124.                   (short) (default_rows ? default_rows : *bios_rows ));
  125.       error = TRUE;
  126.       return (short) (default_rows ? default_rows : *bios_rows);
  127.                                  /* Faster, but not well documented  */
  128.    }
  129.    else
  130.       return info.dmRows;
  131.  
  132. } /* scrsize */
  133.